<?php
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// DLMan by Shedd Technologies International		  				//
// http://www.dlman.com | info@dlman.com							//
// Copyright 2003 by STI, All rights reserved.						//
// ---------------------------------------------------------------- //
// Usage of this software is governed by the terms of GPL. 	    	//
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
$oldversion = "1.1.0";
$newversion = "1.1.1";
$scriptnumber=2;
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
require_once("../global.php");
require_once("../uis.php");
require_once("../config.php");
/*
	Get version number from database!
*/
$version_number=$config->cs['version'];
$thisscript = "upgrade".$scriptnumber.".php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>DLMan Upgrade (<?php echo $oldversion ?> to <?php echo $newversion ?>)</title>
</head>
<body>
<?php
if (!$step) {
  $step=1;
}

// ******************* STEP 1 *******************
if($step==1) {
	if($version_number==$newversion){
		print "<p>WARNING: Your installation is already running the $newversion codebase!</p>";
	}
	elseif($version_number!=$oldversion){
		print "<p>WARNING: Your installation is not running the $oldversion codebase!  This installation script updates from $oldversion.  You should run previous upgrade scripts first!</p>";
	}
  ?>
  <p>This script will upgrade your installation from DLMan <?php echo $oldversion ?> to <?php echo $newversion ?>. If you are upgrading from a version other than <?php echo $oldversion ?>, please run previous upgrade scripts first.</p>
  <ul>
	  <li>Installing a new version: run <i>install.php</i><br><br>
  </ul>
  <?php
  nextstep($step);
}

// ******************* STEP 2 *******************
//update DB
if($step==2) {
	echo "<b>Updating Database ....</b>";
	$sqlcode=array();
	//Load SQL
	if(file_exists("upgrade".$scriptnumber."_data.txt")){
		$file=file("upgrade".$scriptnumber."_data.txt");//read in entire file to an array
		foreach($file as $line){
			$line=trim($line);
			array_push($sqlcode, $line);
		}
	}
	else{
		die("ERROR: No Database Information!");
	}
	
	$err=false;
	foreach($sqlcode as $sql){
		/*
		Codes used in database definition file:
			[%PRE%] for DLMan Table Prefix
			[%FPRE%] for Community Table Prefix
		*/
		$sql=str_replace("[%PRE%]",$mysql['pre'],$sql);
		$sql=str_replace("[%FPRE%]",$mysql['fpre'],$sql);
		
		$result=mysql_query($sql);
		if(!$result){
			die("<br>Problem updating tables!<br><br><pre>$sql</pre><br><br>".mysql_error());
			$err=true;
		}
		else{
			//print "$sql<br>";
		}
	}
	
	if($err!=true){
		//show next step
		print "<p>Success!</p>";
		nextstep($step);
	}
}

// ******************* STEP 3 *******************
if($step==3) {
  // update version
  echo "Updating version number .... ";
  $sql="UPDATE ".$mysql['pre']."settings"." SET version='".$newversion."';";
  $result=mysql_query($sql);
  if(!$result){
	print "Problem updating table!<br><br><pre>$sql</pre><br><br>".mysql_error();
  }

  echo "<p>Upgrade to $newversion completed successfully! <br>Please delete the following directories if you uploaded them: install/ and upgrade/";

  echo "<p>Thank you for choosing DLMan.";
}
?>
</body>
</html>
<?php
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
function nextstep($step){
	?>
	<p><FONT face=Verdana><STRONG><a href="<?php print $PHP_SELF; ?>?step=<?php print $step+1; ?>">Proceed to Next Step --&gt;</a></STRONG></FONT></p>
	<?php
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
?>
